# 当线程中的一个线程执行完，就去执行其他任务
import threading
from concurrent.futures import ThreadPoolExecutor


pool = ThreadPoolExecutor(10)  # 创建2个线程池
LOCK = threading.RLock()
A  = [(1, 2, 3, 4, 5), (5, 6, 7, 8, 9, 10), (5, 6, 7, 8, 9, 10),
      (5, 6, 7, 8, 9, 10), (5, 6, 7, 8, 9, 10), (5, 6, 7, 8, 9, 10),
      (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5),
      (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5),
      (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5),
      (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5)]


total = 0


# 创建任务 来进行累加
def task(tup):
    global total 
    total += sum(tup)
    return total


# 线程池完成时 执行其他任务

def done(response):
    print("任务结束后的返回值: ", response.result())

for j in A:
    feture = pool.submit(task, j)   
    feture.add_done_callback(done)  # 一个线程执行完 在执行这个


# 测试结果
addC = 0
for m in A:
    addC += sum(m)
print(addC)
